$(document).ready(function() {
	$('a', '.control-panel').button();

	$('#sub-indicator').ajaxStart(function() {
		$(this).show();
	}).ajaxStop(function() {
		$(this).hide();
	});

	/* Set tool tips on inputs */
	$(":input[type=text], :input[type=password]", '#signUpForm').focus(
			function(event) {
				var fieldName = $(this).prev().html();
				if (fieldName.indexOf('*') != -1) {
					fieldName = fieldName.substring(0, fieldName
							.indexOf('*'));
				} else if (fieldName.indexOf(':') != -1) {
					fieldName = fieldName.substring(0, fieldName
							.indexOf(':'));
				}
				$('.sidebar h3').html(fieldName).next().html(
						$(this).next('.tooltip').html());
			});

	/* Auto focus on first input */
	$(':input', '#signUpForm').first().focus();

	/* Submit action for signing up */
	$('a[name="submitSignUp"]').bind('click', {
		action : 'sign-up-add',
		form : '#signUpForm',
		error : '.sidebar div',
		success : '.centerWrap'
	}, ajaxSubmitForm);
	
	/* Submit action for signing in */
	$('a[name="submitSignIn"]').bind('click', {
		action : 'sign-in-page',
		form : '#signInForm',
		error : '.sidebar div',
		chainAction: 'member/profile.action'
	}, ajaxSubmitForm);
	
	/* Form reset */
	$('a[name="reset"]').bind('click', {
		form : '#signUpForm',
		error: '.sidebar div'
	}, formReset);
	
	/* Date validation */
	$('#signUpForm select').bind('change', dateValidation);
});